********************************************************************
***** EMPIRICAL ANALYSIS OF SOCIOLOGY:  GENDER AND COLLABORATION (LORENZO DUCTOR, SANJEEV GOYAL AND ANJA PRUMMER)
***** Start: 14.12.2020
***** Last change:  14.09.2021
***** CREATED BY: Lorenzo Ductor (lductor@ugr.es)   
***** OBJECTIVE: Replicate Tables 7, 8, A.1 and Figures A.1-A.4
********************************************************************


/*Table 6, main paper: columns 3-7*/

import delimited "sociologydatabase.csv", encoding(Big5) clear 

gen decade601=1 if year<1965 & year>1959
gen decade602=1 if year>1964 & year<1970

gen decade701=1 if year<1975 & year>1969
gen decade702=1 if year>1974 & year<1980

gen decade801=1 if year<1985 & year>1979
gen decade802=1 if year>1984 & year<1990

gen decade901=1 if year<1995 & year>1989
gen decade902=1 if year>1994 & year<2000

foreach i in decade601 decade602 decade701 decade702 decade801 decade802 decade901 decade902{
panels auth if `i'==1 & femaleapi==1	
}

foreach i in decade601 decade602 decade701 decade702 decade801 decade802 decade901 decade902{
panels auth if `i'==1 & femaleapi==0	
}
panels auth if femaleapi==0
panels auth if femaleapi==1

rename snpaperss5 snpapers5y
foreach i in decade602 decade701 decade702 decade801 decade802 decade901 decade902{
ttest snpapers5y if `i'==1, by(femaleapi) unequal
}
ttest snpapers5y, by(femaleapi) unequal



/*Table 7: Gender differences, Sociological Abstracts, 1963-1999*/

import delimited "sociologydatabase.csv", encoding(Big5) clear 
rename sproddsjr5y sproddJR5y
rename sproddsjr sproddSJR
xtset auth year, yearly
rename snpaperss5 snpapers5y
gen sproddSJR5y=sproddSJR+L.sproddSJR+L2.sproddSJR+L3.sproddSJR+L4.sproddSJR

/*replacing missing values in networks by 0 and adding missing dummies*/
foreach i in degree strengthppaper clustering coauthorship5y{ 
    gen d`i'=1 if missing(`i') & snpapers5y!=.
	replace d`i'=0 if missing(d`i') & snpapers5y!=.
	replace `i'=0 if missing(`i') & snpapers5y!=.
}


/*Adding Coauthors' characteristics*/

merge 1:1 auth year using neighchar_5y
drop if _merge==2

/* Creating Coauthors' experience*/
rename avgtcof avgtcoma
rename avgtcom avgtcof
rename avgtcoma avgtcom
rename namecof namecoma 
rename namecom namecof
rename namecoma namecom 

replace avgtcom=0 if namecom==0
replace avgtcof=0 if namecof==0


gen ncoauthors=namecom+namecof

gen fmale=namecom/ncoauthors
gen ffemale=namecof/ncoauthors

replace fmale=0 if namecom==0
replace ffemale=0 if namecof==0

gen avgcot=avgtcom*fmale+avgtcof*ffemale


/*Creating Coauthors' output*/
gen avnetprodm=(netprodm)/namecom
gen avnetprodf=(netprodf)/namecof
gen avnetprod=(netprodf+netprodm)/(namecom+namecof)
gen lavnetprod=log(avnetprod+1)
/*replacing missing values in networks by 0 and adding missing dummies*/
foreach i in avgcot lavnetprod{ 
    gen d`i'=1 if missing(`i') & snpapers5y!=.
	replace d`i'=0 if missing(d`i') & snpapers5y!=.
	replace `i'=0 if missing(`i') & snpapers5y!=.
}


reg sproddSJR5y femaleapi i.year i.t sj1-sj149, vce(cluster auth)
gen sap=1 if e(sample) /*defining common sample*/

/*# Publications, adjusted mean*/
reg snpapers5y i.femaleapi i.year i.t sj1-sj149 if sap==1, vce(cluster auth)  
margins femaleapi, atmeans 
/*# Publications, mean*/
reg snpapers5y i.femaleapi if sap==1, vce(cluster auth)  
margins femaleapi, atmeans 

/*SJR, mean*/
reg sproddSJR5y i.femaleapi if sap==1, vce(cluster auth)
margins femaleapi, atmeans 
/*SJR, adjusted mean*/
reg sproddSJR5y i.femaleapi i.year i.t sj1-sj149 if sap==1, vce(cluster auth)
margins femaleapi, atmeans 

/*Log(SJR+1), adjusted mean*/
gen lprod5=log(sproddJR5y+1)
reg lprod5 i.femaleapi i.year i.t sj1-sj149 if sap==1, vce(cluster auth)
margins femaleapi, atmeans 
/*Log(SJR+1), mean*/
reg lprod5 i.femaleapi if sap==1, vce(cluster auth)
margins femaleapi, atmeans 



set more off

/*Degree, adjusted mean*/
reg degree i.femaleapi ddegree i.year i.t sj2-sj149, vce(cluster auth)
margins femaleapi, at(ddegree==0)
/*Degree, mean*/
reg degree i.femaleapi ddegree, vce(cluster auth)
margins femaleapi, at(ddegree==0)
/*Clustering, adjusted mean*/
reg clustering dclustering i.femaleapi i.year i.t sj2-sj149, vce(cluster auth)
margins femaleapi, at(dclustering ==0)
/*Clustering, mean*/
reg clustering dclustering i.femaleapi, vce(cluster auth)
margins femaleapi, at(dclustering ==0)
/*Strength, adjusted mean*/
reg strengthppaper dstrengthppaper i.femaleapi i.year i.t sj2-sj149, vce(cluster auth)
margins femaleapi, at(dstrengthppaper ==0)
/*Strength, mean*/
reg strengthppaper dstrengthppaper i.femaleapi, vce(cluster auth)
margins femaleapi, at(dstrengthppaper ==0)

/*Co-authorship, adjusted mean*/
reg coauthorship5y dcoauthorship5y i.femaleapi i.year i.t sj2-sj149, vce(cluster auth)
margins femaleapi, at(dcoauthorship5y==0)
/*Co-authorship, mean*/
reg coauthorship5y dcoauthorship5y i.femaleapi, vce(cluster auth)
margins femaleapi, at(dcoauthorship5y==0)

/*Average Co-author Experience, adjusted mean*/
reg avgcot davgcot i.femaleapi i.year i.t sj2-sj149, vce(cluster auth)
margins femaleapi, atmeans
/*Average Co-author Experience, mean*/
reg avgcot davgcot i.femaleapi, vce(cluster auth)
margins femaleapi, atmeans
/* Log(SJRc +1), adjusted mean*/
reg lavnetprod dlavnetprod i.femaleapi i.year i.t sj2-sj149, vce(cluster auth)
margins femaleapi, atmeans
/* Log(SJRc +1), mean*/
reg lavnetprod dlavnetprod  i.femaleapi, vce(cluster auth)
margins femaleapi, atmeans

/*********TABLE 8: Gender, Networks and Future output (JCR)***********/


gen lcproddl5=log(cproddl5+1)

xtset auth year, yearly
foreach i in degree strengthppaper clustering lavnetprod avgcot{
	gen `i'l5=L5.`i'
}

foreach i in  degree strengthppaper clustering lavnetprod avgcot{
	gen d`i'l5=1 if missing(`i'l5) 
	replace d`i'l5=0 if missing(d`i'l5)
    replace `i'l5=0 if missing(`i'l5)
}

reg lprod5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year, vce(cluster auth)
gen es2=1 if e(sample)	   

set more off	 
  
reg lprod5 i.femaleapi sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) replace

reg lprod5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 degreel5 ddegreel5 i.femaleapi sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year ddegreel5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 degreel5 ddegreel5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year ddegreel5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 strengthppaperl5 dstrengthppaperl5 i.femaleapi sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year dstrengthppaperl5 ) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 strengthppaperl5 dstrengthppaperl5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year dstrengthppaperl5 ) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 clusteringl5 dclusteringl5 i.femaleapi sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year dclusteringl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 clusteringl5 dclusteringl5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year dclusteringl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi  sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lprod5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


/*testing if the differences are statistically significant*/
reg lprod5 femaleapi sj2-sj149 i.t i.year if es2==1
estimates store m1
reg lprod5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m2
reg lprod5 degreel5 ddegreel5 femaleapi sj2-sj149 i.t i.year if es2==1
estimates store m3
reg lprod5 degreel5 ddegreel5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m4
reg lprod5 strengthppaperl5 dstrengthppaperl5 femaleapi sj2-sj149 i.t i.year if es2==1
estimates store m5
reg lprod5 strengthppaperl5 dstrengthppaperl5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m6
reg lprod5 clusteringl5 dclusteringl5 femaleapi sj2-sj149 i.t i.year if es2==1
estimates store m7
reg lprod5 clusteringl5 dclusteringl5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m8
reg lprod5 ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 femaleapi  sj2-sj149 i.t i.year if es2==1
estimates store m9
reg lprod5 ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 femaleapi lcproddl5  sj2-sj149 i.t i.year if es2==1
estimates store m10

suest m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, noomitted  vce(cluster auth)
test [m1_mean]femaleapi = [m2_mean]femaleapi 
test [m1_mean]femaleapi = [m3_mean]femaleapi 
test [m1_mean]femaleapi = [m4_mean]femaleapi 
test [m1_mean]femaleapi = [m5_mean]femaleapi 
test [m1_mean]femaleapi = [m6_mean]femaleapi 
test [m1_mean]femaleapi = [m7_mean]femaleapi 
test [m1_mean]femaleapi = [m8_mean]femaleapi 
test [m1_mean]femaleapi = [m9_mean]femaleapi 
test [m1_mean]femaleapi = [m10_mean]femaleapi


test [m2_mean]femaleapi = [m3_mean]femaleapi 
test [m2_mean]femaleapi = [m4_mean]femaleapi 
test [m2_mean]femaleapi = [m5_mean]femaleapi 
test [m2_mean]femaleapi = [m6_mean]femaleapi 
test [m2_mean]femaleapi = [m7_mean]femaleapi 
test [m2_mean]femaleapi = [m8_mean]femaleapi 
test [m2_mean]femaleapi = [m9_mean]femaleapi 
test [m2_mean]femaleapi = [m10_mean]femaleapi


/********************SECTION A OF THE ONLINE APPENDIX***************************/
/*******************************************************************************/

/*Figure A.1: Share of Female Authors, Sociological Abstracts, 1963-1999*/
import delimited "sociologydatabase.csv", encoding(Big5) clear 
keep auth year femaleapi
gen x=1
collapse (sum) x, by(year femaleapi) 
drop if femaleapi==.
bys year: egen total=sum(x)
gen share=x/total
keep if femaleapi==1
tsset year, yearly
tsline share if year>1962 & year<2000, lcolor(black) lwidth(thick) lpattern(solid) ytitle("Fraction of women") xtitle("Year") legend(label(1 female) label(2 male)) scheme(s1color) xlabel(1960(5)2000)	
graph export "wft_sociology.pdf", as(pdf) replace




import delimited "sociologydatabase.csv", encoding(Big5) clear 
rename sproddsjr5y sproddJR5y
rename sproddsjr sproddSJR
rename snpaperss5 snpapers5y
xtset auth year, yearly
gen sproddSJR5y=sproddSJR+L.sproddSJR+L2.sproddSJR+L3.sproddSJR+L4.sproddSJR

/*replacing missing values in networks by 0 and adding missing dummies*/
foreach i in degree strengthppaper clustering coauthorship5y{ 
    gen d`i'=1 if missing(`i') & snpapers5y!=.
	replace d`i'=0 if missing(d`i') & snpapers5y!=.
	replace `i'=0 if missing(`i') & snpapers5y!=.
}

merge 1:1 auth year using neighchar_5y
drop if _merge==2

/*Couathors' experience*/
rename avgtcof avgtcoma
rename avgtcom avgtcof
rename avgtcoma avgtcom
rename namecof namecoma 
rename namecom namecof
rename namecoma namecom 

replace avgtcom=0 if namecom==0
replace avgtcof=0 if namecof==0


gen ncoauthors=namecom+namecof

gen fmale=namecom/ncoauthors
gen ffemale=namecof/ncoauthors

replace fmale=0 if namecom==0
replace ffemale=0 if namecof==0

gen avgcot=avgtcom*fmale+avgtcof*ffemale


/*Coauthors' output*/
gen avnetprodm=(netprodm)/namecom
gen avnetprodf=(netprodf)/namecof
gen avnetprod=(netprodf+netprodm)/(namecom+namecof)
gen lavnetprod=log(avnetprod+1)

/*replacing missing values in networks by 0 and adding missing dummies*/
foreach i in avgcot lavnetprod{ 
    gen d`i'=1 if missing(`i') & snpapers5y!=.
	replace d`i'=0 if missing(d`i') & snpapers5y!=.
	replace `i'=0 if missing(`i') & snpapers5y!=.
}


set more off

gen lprod5=log(sproddJR5y+1)
gen lcproddl5=log(cproddl5+1)

xtset auth year, yearly
foreach i in degree strengthppaper clustering lavnetprod avgcot{
	gen `i'l5=L5.`i'
}

foreach i in  degree strengthppaper clustering lavnetprod avgcot{
	gen d`i'l5=1 if missing(`i'l5) 
	replace d`i'l5=0 if missing(d`i'l5)
    replace `i'l5=0 if missing(`i'l5)
}

/*Table A.1: Gender, Characteristics of Co-authors and Output in Sociolog*/

set more off	 
reg lprod5  lavnetprodl5 dlavnetprodl5 i.femaleapi sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) replace


reg lprod5 lavnetprodl5 dlavnetprodl5  i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg lprod5 avgcotl5 davgcotl5 i.femaleapi sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg lprod5 avgcotl5 davgcotl5  i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5  i.femaleapi sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5  i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5  degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi  sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5  degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sj2-sj149 i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg lprod5  lavnetprodl5 dlavnetprodl5 femaleapi sj2-sj149 i.t i.year if es2==1
estimates store m3

reg lprod5 lavnetprodl5 dlavnetprodl5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m4

reg lprod5 avgcotl5 davgcotl5 femaleapi sj2-sj149 i.t i.year if es2==1
estimates store m5

reg lprod5 avgcotl5 davgcotl5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m6

reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5 femaleapi sj2-sj149 i.t i.year if es2==1
estimates store m7

reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m8

reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 femaleapi  sj2-sj149 i.t i.year if es2==1
estimates store m9

reg lprod5 lavnetprodl5 dlavnetprodl5 avgcotl5 davgcotl5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 femaleapi lcproddl5 sj2-sj149 i.t i.year if es2==1
estimates store m10


suest m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, noomitted  vce(cluster auth)
test [m1_mean]femaleapi = [m2_mean]femaleapi 
test [m1_mean]femaleapi = [m3_mean]femaleapi 
test [m1_mean]femaleapi = [m4_mean]femaleapi 
test [m1_mean]femaleapi = [m5_mean]femaleapi 
test [m1_mean]femaleapi = [m6_mean]femaleapi 
test [m1_mean]femaleapi = [m7_mean]femaleapi 
test [m1_mean]femaleapi = [m8_mean]femaleapi 
test [m1_mean]femaleapi = [m9_mean]femaleapi 
test [m1_mean]femaleapi = [m10_mean]femaleapi


test [m2_mean]femaleapi = [m3_mean]femaleapi 
test [m2_mean]femaleapi = [m4_mean]femaleapi 
test [m2_mean]femaleapi = [m5_mean]femaleapi 
test [m2_mean]femaleapi = [m6_mean]femaleapi 
test [m2_mean]femaleapi = [m7_mean]femaleapi 
test [m2_mean]femaleapi = [m8_mean]femaleapi 
test [m2_mean]femaleapi = [m9_mean]femaleapi 
test [m2_mean]femaleapi = [m10_mean]femaleapi


/*Figure A.1 (left plots), A.2 (left plots) and A.3*/

import delimited "sociologydatabase.csv", encoding(Big5) clear 
rename sproddsjr5y sproddJR5y
rename sproddsjr sproddSJR
rename snpaperss5 snpapers5y
xtset auth year, yearly
gen sproddSJR5y=sproddSJR+L.sproddSJR+L2.sproddSJR+L3.sproddSJR+L4.sproddSJR

merge 1:1 auth year using neighchar_5y
drop if _merge==2
rename avgtcof avgtcoma
rename avgtcom avgtcof
rename avgtcoma avgtcom
rename namecof namecoma 
rename namecom namecof
rename namecoma namecom 
gen ncoauthors=namecom+namecof
gen fmale=namecom/ncoauthors
gen ffemale=namecof/ncoauthors
gen avgcot=avgtcom*fmale+avgtcof*ffemale

/*Coauthors' output*/
gen avnetprodm=(netprodm)/namecom
gen avnetprodf=(netprodf)/namecof
gen avnetprod=(netprodf+netprodm)/(namecom+namecof)
gen lavnetprod=log(avnetprod+1)
/*replacing missing values in networks by 0 and adding missing dummies*/
foreach i in avgcot lavnetprod{ 
    gen d`i'=1 if missing(`i') & snpapers5y!=.
	replace d`i'=0 if missing(d`i') & snpapers5y!=.
	replace `i'=0 if missing(`i') & snpapers5y!=.
}

set more off

gen lprod5=log(sproddJR5y+1)
gen lcproddl5=log(cproddl5+1)

xtset auth year, yearly
reg lprod5 i.femaleapi lcproddl5 sj2-sj149 i.t i.year, vce(cluster auth)
gen es2=1 if e(sample)	   

keep if es2==1

*gen sproddSJR5y=sproddSJR+L.sproddSJR+L2.sproddSJR+L3.sproddSJR+L4.sproddSJR


keep auth year femaleapi sproddSJR5y snpapers5y degree clustering strengthppaper avgcot
collapse (mean) sproddSJR5y snpapers5y degree clustering strengthppaper avgcot, by(year femaleapi) 
drop if femaleapi==.

reshape wide sproddSJR5y snpapers5y degree clustering strengthppaper avgcot, i(year) j(femaleapi)
tsset year, yearly
gen sproddSJR5dif=sproddSJR5y0-sproddSJR5y1
gen mprod5diff=sproddSJR5y1-sproddSJR5y0
gen mpapersdiff=snpapers5y1-snpapers5y0
gen degreediff=degree1-degree0
gen clusterdiff=clustering1-clustering0
gen strengthdiff=strengthppaper1-strengthppaper0
gen avgcotdiff=avgcot1-avgcot0

drop if year<1967

twoway (tsline snpapers5y0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline snpapers5y1, lpattern(shortdash) lwidth(thick)) ///
	   (tsline mpapersdiff,  color(black) lwidth(thick)) if year<2017, ///
       ytitle("Avg. # of publications per author") ///
	    xlabel(1970(5)2000) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
		ylabel(-1(1)3) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "snpapers5diff_soc.pdf", as(pdf) replace
	   
	   
tsset year, yearly
twoway (tsline sproddSJR5y0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline sproddSJR5y1, lpattern(shortdash) lwidth(thick)) ///
	   (tsline mprod5diff, color(black) lwidth(thick)), ///
       ytitle("Average Research Output") ///
	    xlabel(1970(5)2000) ///
		ylabel(-2(1)2) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) 
graph export "prod5diff_soc.pdf", as(pdf) replace

drop if year<1975
twoway (tsline degree0 if year>1974, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline degree1 if year>1974, lpattern(dash) lwidth(thick)) ///
	   (tsline degreediff if year>1974,  color(black) lwidth(thick)), ///
       ytitle("Degree") ///
	    xlabel(1975(5)2000) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
		ylabel(-1(1)4) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "degreediff_soc.pdf", as(pdf) replace


twoway (tsline clustering0 , color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline clustering1, lpattern(dash) lwidth(thick)) ///
	   (tsline clusterdiff,  color(black) lwidth(thick)), ///
       ytitle("Clustering") ///
	   xlabel(1975(5)2000) ///
		ylabel(0(0.2)0.8) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "clusterdiff_soc.pdf", as(pdf) replace

twoway (tsline strengthppaper0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline strengthppaper1, lpattern(dash) lwidth(thick)) ///
	   (tsline strengthdiff,  color(black) lwidth(thick)), ///
       ytitle("Strength") ///
	   xlabel(1975(5)2000) ///
		ylabel(0(0.2)0.8) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "strengthdiff_soc.pdf", as(pdf) replace



/*Figure A.3: Coauthors' seniority across career time*/

import delimited "sociologydatabase.csv", encoding(Big5) clear 
rename snpaperss5 snpapers5y
merge 1:1 auth year using neighchar_5y
drop if _merge==2

/*Couathors' experience*/
rename avgtcof avgtcoma
rename avgtcom avgtcof
rename avgtcoma avgtcom
rename namecof namecoma 
rename namecom namecof
rename namecoma namecom 

replace avgtcom=0 if namecom==0
replace avgtcof=0 if namecof==0


gen ncoauthors=namecom+namecof

gen fmale=namecom/ncoauthors
gen ffemale=namecof/ncoauthors

replace fmale=0 if namecom==0
replace ffemale=0 if namecof==0

gen avgcot=avgtcom*fmale+avgtcof*ffemale

set more off
xtset auth year, yearly
gen lprod5=log(sproddsjr5y+1)

keep auth year t avgcot femaleapi
collapse (mean) avgcot, by(t femaleapi) 
drop if femaleapi==.

reshape wide avgcot, i(t) j(femaleapi)
tsset t, yearly
gen avgcotdiff=avgcot1-avgcot0
twoway (tsline avgcot0 if t<22, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline avgcot1 if t<22, lpattern(dash) lwidth(thick)), ///	      
       ytitle("Average coauthors' experience") ///
	   xlabel(1(5)20) ///
	   ylabel(0(2)10) ///
       xtitle("Career time")  legend(order(1 "Male" 2 "Female")) scheme(s1color) 
graph export "avgtco_t_soc.pdf", as(pdf) replace


	
/*Figures A.3: Adjusted means over time*/


import delimited "sociologydatabase.csv", encoding(Big5) clear 
rename sproddsjr5y sproddJR5y
rename sproddsjr sproddSJR
rename snpaperss5 snpapers5y
xtset auth year, yearly
gen sproddSJR5y=sproddSJR+L.sproddSJR+L2.sproddSJR+L3.sproddSJR+L4.sproddSJR

/*Regressions to obtain the adjusted means differences*/
reg sproddSJR5y i.femaleapi##i.year i.t sj1-sj149, vce(cluster auth)
gen sap=1 if e(sample)
parmest, saving(outputacrossyear_pols, replace)
margins femaleapi, at(year=1967 year=1999) 
testparm femaleapi#year

reg snpapers5y i.femaleapi##i.year i.year i.t sj1-sj149 if sap==1, vce(cluster auth)  
parmest, saving(papersacrossyear_pols, replace)
margins femaleapi, at(year=1967 year=1999)
testparm femaleapi#year


/*replacing missing values in networks by 0 and adding missing dummies*/
foreach i in degree strengthppaper clustering{ 
    gen d`i'=1 if missing(`i') & snpapers5y!=.
	replace d`i'=0 if missing(d`i') & snpapers5y!=.
	replace `i'=0 if missing(`i') & snpapers5y!=.
}

set more off

reg degree ddegree i.femaleapi##i.year i.t sj2-sj149, vce(cluster auth)  
margins femaleapi, at(year=1980 year=2017)
parmest, saving(degreeacrossyear_pols, replace)
test 1985.year#1.femaleapi+1.femaleapi=0 
testparm femaleapi#year 

reg strengthppaper dstrengthppaper i.femaleapi##i.year i.t sj2-sj149, vce(cluster auth)
parmest, saving(strengthacrossyear_pols, replace)
test 1988.year#1.femaleapi+1.femaleapi=0 
testparm femaleapi#year

reg clustering dclustering i.femaleapi##i.year i.t sj2-sj149, vce(cluster auth)
parmest, saving(clusteringacrossyear_pols, replace)
test 1988.year#1.femaleapi+1.femaleapi=0 
testparm femaleapi#year 



/*PLOTS*/

use papersacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1968+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1968(5)2000) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(0(0.2)1)
graph export papers_pols_soc.pdf, replace



use outputacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1968+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1968(5)2000) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(0(0.2)1.4)
graph export output_pols_soc.pdf, replace



use degreeacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1968+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1968(5)2000) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-0.4(0.2)0.4)
graph export degdiff_pols_soc.pdf, replace


use strengthacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1968+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1968(5)2000) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-0.2(0.05)0)
graph export istdiffb_pols_soc.pdf, replace

	   
use clusteringacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1968+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1968(5)2000) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-0.2(0.05)0)
graph export clustdiff_pols_soc.pdf, replace
	  	  	   
******************************************************************************	 

